use std::{cmp::Ordering, io};
use rand::Rng;

fn main() {
    println!("Guess the number!");

    let secret_number = rand::thread_rng().gen_range(1..=100);

    loop {
        println!("please enter you guess:");
        let mut guess = String::new();

        io::stdin()
        .read_line(&mut guess)
        .expect("failed to read line");
    
        println!("you guessed:{}", guess);
    
        let guess : i32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => {
                println!("you type is not a valid num in [1,100]");
                continue;},
        };
        
        // 比较秘密数字和猜测值
        match guess.cmp(&secret_number) {
            Ordering::Less => println!("too small"),
            Ordering::Equal => {
                println!("you win");
                break;
            },
            Ordering::Greater => println!("too big"),
        }
    }

    

    


}
